home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / CDEF-DeBugger 2.0 ƒ / events.c < prev    next >
Text File  |  1995-05-31  |  6KB  |  281 lines

  1. // prototypes
  2. void    EventLoop( void );
  3. void     HandleMouseDown( EventRecord myEvent );
  4. void     HandleKeyPress( EventRecord myEvent );
  5. void    HandleContents( Point clickPnt, WindowPtr theWindow );
  6. void    HandleMenuChoice( long menuChoice );
  7. void    AppleChoice( int theItem );
  8. void    FileChoice( int theItem );
  9. void    EditChoice( int theItem );
  10. void    DoWindowUpdates( WindowPtr theWindow );
  11.  
  12. // globals
  13. extern MenuHandle            gAppleMenu;
  14. extern Boolean                gDone;
  15. extern Main                    myMain;
  16.  
  17. /****************************************************************************
  18.  
  19.          Main Event Loop
  20.  
  21. *****************************************************************************/
  22. void    EventLoop( void )
  23. {
  24.     EventRecord                myEvent;
  25.     
  26.     if( WaitNextEvent( everyEvent, &myEvent, 30, 0 ))
  27.     {    
  28.         switch( myEvent.what ) 
  29.         {
  30.             case mouseDown:
  31.                 HandleMouseDown( myEvent );
  32.                 break;
  33.                         
  34.             case keyDown:            
  35.             case autoKey:
  36.                 HandleKeyPress( myEvent );
  37.                 break;
  38.                 
  39.             case updateEvt:
  40.                 DoWindowUpdates( (WindowPtr)myEvent.message );
  41.                 break;
  42.                 
  43.             case diskEvt:
  44.                 break;
  45.                 
  46.             case activateEvt:
  47.                 break;
  48.                 
  49.             case app4Evt:
  50.                 break; 
  51.                 
  52.             default:
  53.                 break;
  54.         }
  55.     }
  56. }
  57.  
  58. /****************************************************************************
  59.  
  60.         Handle any MouseDown Events
  61.          
  62. *****************************************************************************/
  63. void     HandleMouseDown( EventRecord myEvent )
  64. {
  65.     short        thePart;
  66.     WindowPtr    whichWindow;
  67.     
  68.     thePart = FindWindow( myEvent.where, &whichWindow );
  69.     
  70.     switch( thePart )
  71.     {
  72.         case inSysWindow:
  73.             SystemClick( &myEvent, whichWindow );
  74.             break;
  75.                                 
  76.         case inMenuBar:
  77.             HandleMenuChoice( MenuSelect( myEvent.where ));
  78.             break;
  79.                                 
  80.         case inContent:
  81.             SelectWindow( whichWindow );
  82.             HandleContents( myEvent.where, whichWindow );
  83.             break;
  84.                                 
  85.         case inDrag:
  86.             DragWindow( whichWindow, myEvent.where, &qd.screenBits.bounds );
  87.             break;
  88.                                 
  89.         case inGrow:
  90.             break;
  91.                                 
  92.         case inGoAway:
  93.             if( TrackGoAway( whichWindow, myEvent.where ) ) {
  94.                 gDone = TRUE;
  95.             }
  96.             break;
  97.     
  98.         case inZoomIn:
  99.             break;
  100.     
  101.         case inZoomOut:
  102.             break;
  103.     
  104.         default:
  105.             break;
  106.     }
  107. }
  108.  
  109. /****************************************************************************
  110.  
  111.         Handle any KeyDown Events
  112.          
  113. *****************************************************************************/
  114. void     HandleKeyPress( EventRecord    myEvent )
  115. {
  116.     char            key;
  117.         
  118.     key = myEvent.message & charCodeMask;
  119.     if( myEvent.modifiers & cmdKey ) {
  120.         if( myEvent.what == keyDown ) {
  121.             HandleMenuChoice( MenuKey( key ));
  122.         }
  123.     }
  124. }
  125.  
  126. /****************************************************************************
  127.  
  128.         Handle Contents if clicked in my window.
  129.          
  130. *****************************************************************************/
  131. void    HandleContents( Point clickPnt, WindowPtr whichWindow )
  132. {
  133.     short             partCode, iPartCode, whatWindow;
  134.     ControlHandle    theControl;
  135.     
  136.     whatWindow = GetWRefCon( whichWindow );
  137.     GlobalToLocal( &clickPnt );
  138.     
  139.     switch( whatWindow ) 
  140.     {
  141.         case MAIN_WINDOW:
  142.             partCode = FindControl( clickPnt, whichWindow, &theControl );
  143.             if( partCode != 0 ) {
  144.                 iPartCode = TrackControl( theControl, clickPnt, 0 );
  145.                 
  146.             }
  147.             break;
  148.     }
  149. }
  150.  
  151. /****************************************************************************
  152.  
  153.         HandleMenuChoice
  154.          
  155. *****************************************************************************/
  156. void    HandleMenuChoice( long menuChoice )
  157. {
  158.     short    theMenu, theItem;
  159.     
  160.     if( menuChoice != 0 )
  161.     {    
  162.         
  163.         theMenu = HiWord( menuChoice );
  164.         theItem = LoWord( menuChoice );
  165.         switch( theMenu ) {
  166.             case MENU_APPLE:
  167.                 AppleChoice( theItem );
  168.                 break;
  169.                 
  170.             case MENU_FILE:
  171.                 FileChoice( theItem );
  172.                 break;
  173.                 
  174.             case MENU_EDIT:
  175.                 EditChoice( theItem );
  176.                 break;
  177.             
  178.             //Add more case's to handle any additional menu's
  179.         }
  180.     }
  181.     HiliteMenu( 0 );
  182. }
  183.  
  184. /****************************************************************************
  185.  
  186.         User selects the 'Apple Menu'
  187.          
  188. *****************************************************************************/
  189. void    AppleChoice( int theItem )
  190. {
  191.     Str255        accName;
  192.     int            accNumber;
  193.     short        itemNumber;
  194.     
  195.     switch( theItem ) 
  196.     {
  197.         //Declare any of your menus for Edit here.
  198.         //Be Sure to update the "MenuDeclarations.h" file
  199.         
  200.         case APPLE_ABOUT:
  201.             CreateMySplashWindow();
  202.             break;
  203.             
  204.         default:
  205.             GetItem( gAppleMenu, theItem, accName );
  206.             accNumber = OpenDeskAcc( accName );
  207.             break;
  208.     }
  209. }
  210.  
  211. /****************************************************************************
  212.  
  213.         User selects the 'File Menu'
  214.          
  215. *****************************************************************************/
  216. void    FileChoice( int theItem )
  217. {
  218.     switch( theItem ) 
  219.     {
  220.         //Declare any of your menus for File here.
  221.         //Be Sure to update the "MenuDeclarations.h" file
  222.         
  223.         case FILE_QUIT:
  224.             gDone = TRUE;
  225.             break;
  226.     }
  227. }
  228.  
  229. /****************************************************************************
  230.  
  231.         User selects the 'Edit Menu'
  232.          
  233. *****************************************************************************/
  234. void    EditChoice( int theItem )
  235. {
  236.     switch( theItem ) 
  237.     {
  238.         //Declare any of your menus for Edit here.
  239.         //Be Sure to update the "MenuDeclarations.h" file
  240.         
  241.         case EDIT_UNDO:
  242.             break;
  243.             
  244.         case EDIT_CUT:
  245.             break;
  246.             
  247.         case EDIT_COPY:
  248.             break;
  249.             
  250.         case EDIT_PASTE:
  251.             break;
  252.             
  253.         case EDIT_CLEAR:
  254.             break;
  255.             
  256.         case EDIT_SELECTALL:
  257.             break;
  258.     }
  259. }
  260.  
  261. /****************************************************************************
  262.  
  263.         Handles any window updates.
  264.          
  265. *****************************************************************************/
  266. void    DoWindowUpdates( WindowPtr theWindow )
  267. {
  268.     GrafPtr        savedPort;
  269.         
  270.     GetPort( &savedPort );
  271.     
  272.     if( GetWRefCon( theWindow ) == MAIN_WINDOW ) 
  273.     {
  274.         SetPort( myMain.window );
  275.         BeginUpdate( myMain.window );
  276.         UpdateMainWindow( myMain.window );
  277.         EndUpdate( myMain.window );
  278.     }
  279.     
  280.     SetPort( savedPort );
  281. }